package com.example.wangzh.developkit.base;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import com.example.wangzh.developkit.R;

import butterknife.ButterKnife;

/**
 * Created by wangzh on 2017/10/19.
 */

public class BaseActivity extends AppCompatActivity implements View.OnClickListener {
    private final static long CLICK_INTERVAL = 1000;
    private long clickTime;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());
        ButterKnife.bind(this);
        initData();
        initView();
    }

    protected int getLayout() {
        return R.layout.activity_main;
    }

    protected void initData() {
    }

    protected void initView() {
    }

    /**
     * @param view
     * @Description: 点击事件
     * @return：void
     */
    protected void click(View view) {
    }

    @Override
    public final void onClick(View v) {
        boolean fastClick = false;
        Object object = v.getTag(R.id.fast_click);
        if (object != null) {
            fastClick = (Boolean) object;
        }
        if (!fastClick && System.currentTimeMillis() - clickTime < CLICK_INTERVAL) {
            return;
        }
        clickTime = System.currentTimeMillis();
        click(v);
    }

    protected void registerFastClick(View v) {
        v.setTag(R.id.fast_click, true);
    }
}
